package com.zyj.springboot.controller;

import com.zyj.springboot.dto.UserDto;
import com.zyj.springboot.srevice.BannerServiceImpl;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : zhouyajun
 * @date : 2020-05-14
 */

@RestController
@Validated
public class UserController {


    @GetMapping("/v2/user/info")
    public UserDto getUserInfo(@RequestParam @Length(min = 2, max = 5, message = "用户名长度必须在2-5的范围")
                                           String username){
        return UserDto.builder()
                .userId(1000)
                .username(username)
                .build();
    }

    @GetMapping("/v2/user/{username}")
    public UserDto getUserInfoV2(@PathVariable @Length(min = 2, max = 5, message = "用户名长度必须在2-5的范围") String username){
        return UserDto.builder()
                .userId(2000)
                .username(username)
                .build();
    }

    @RequestMapping("/v2/user/create")
    public UserDto createUser(@RequestBody @Validated  UserDto userDto){
        userDto.setUserId(1000);
        return userDto;
    }
}
